<template>
    <div class="programModify">
        <el-form 
            ref="ruleForm" 
            label-width="100px"
            :model="ruleForm"
            :rules="rules">
            <el-form-item label="小程序名称" prop="appname">
                <el-select v-model="ruleForm.myappname" placeholder="请选择小程序名称">
                    <el-option label='请选择' value='' ></el-option>
                    <el-option :label=item.appname :value=item.appname v-for="(item,index) in options" :key="index">{{item.appname}}</el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="模块名称" prop="type">
                <el-input v-model="ruleForm.type"></el-input>
            </el-form-item>

            <el-upload  class="upload-demo" action="https://www.yyjpai.com/index/operate/uploadsImg" :on-success=handleAvatarSuccess name="file" list-type="picture">
                <el-button size="small" type="primary">点击上传</el-button>
                <div slot="tip" class="el-upload__tip">图片大小为1M之内</div>
            </el-upload>


            <el-upload class="upload-demo"  action="https://www.yyjpai.com/index/operate/uploadsImg" name="file" :on-success=handleAvatarSuccess1 list-type="picture">
                <el-button size="small" type="primary">点击上传</el-button>
                <div slot="tip" class="el-upload__tip">二维码图片大小为1M之内</div>
            </el-upload>

            
            <el-form-item label="产品名称" prop="name">
                <el-input v-model="ruleForm.name"></el-input>
            </el-form-item>
            <el-form-item label="APPID" prop="appid">
                <el-input v-model="ruleForm.appid"></el-input>
            </el-form-item>
            <el-form-item label="跳转路径" prop="pages">
                <el-input v-model="ruleForm.pages"></el-input>
            </el-form-item>
            <el-form-item label="携带参数" prop="param">
                <el-input v-model="ruleForm.param"></el-input>
            </el-form-item>
            <el-form-item label="游戏人数">
                <el-input v-model.number="ruleForm.total_person" type="total_person"></el-input>
            </el-form-item>
            <el-form-item label="排序" prop="sort">
                <el-input v-model.number="ruleForm.sort" type="number"></el-input>
            </el-form-item>
        </el-form>
       <el-button @click="submitForm('ruleForm')" size="medium" class="addSubimit">提交</el-button>
    </div>
</template>
<script>
import { AddData,getChannel } from '@/assets/js'
export default {
    data(){
        return {
            options:[],
            ruleForm:{
                type:'',//模块名称
                logo:'',//模块名称
                poster:'',//二维码名称
                name:'',//文字
                myappname:'',//小程序名称
                appid:'',//小程序APPID
                pages:'',//小程序跳转路径
                total_person:'',//游戏人数
                sort:''//排序
            },
            rules:{
                type:[
                    { required: true, message: '请输入模块名称', trigger: 'blur' }
                ],
                name:[
                    { required: true, message: '请输入文字', trigger: 'blur' }
                ],
                myappname:[
                    { required: true, message: '请输入小程序名称', trigger: 'blur' }
                ],
                appid:[
                    { required: true, message: '请输入小程序APPID', trigger: 'blur' }
                ],
                sort:[
                    { required: true, message: '请输入排序', trigger: 'blur' }
                ],
            }
        }
    },
    mounted:function(){
       getChannel(this)
    },
    methods:{
        handleAvatarSuccess(res, file) {//上传成功之后
            this.ruleForm.logo = file.response.data.logo
        },
        handleAvatarSuccess1(res, file) {//上传成功之后
            this.ruleForm.poster = file.response.data.logo
        },
        submitForm:function(e){
            let data = {
                type:this.ruleForm.type,
                name:this.ruleForm.name,
                poster:this.ruleForm.poster,
                myappname:this.ruleForm.myappname,
                appid:this.ruleForm.appid,
                pages:this.ruleForm.pages,
                param:this.ruleForm.param,
                total_person:this.ruleForm.total_person,
                sort:this.ruleForm.sort,
                logo:this.ruleForm.logo,
            }
            if(this.ruleForm.logo==''){
                this.$notify.error({
                    title: '必须选择图片哦！'
                });
            }
            else{
                 AddData(this,e,data,'jump_program/addJumpProgram')
            }
           
        }
    }
}
</script>